<?php
/**
 * 修改更改的版本,目前是为了使用方便，堆积在一起
 * 发送邮件类
 * 后期改成自己的mail server
 */
require_once('lib/mail/class.phpmailer.php');
require_once('lib/mail/class.smtp.php');

class Mailer{

	private $_mail;

	function __construct(){
		$this->_mail = new PHPMailer(true);
		$this->init();
	}

	private function init(){

    $this->_mail->IsSMTP();
  	$this->_mail->SMTPAuth   = true;
		$this->_mail->CharSet    = 'UTF-8';
		$this->auth();
	}

	public function host(){

  	$this->_mail->Host	= "smtp.163.com";
  	$this->_mail->Port	= 25;

	}

	public function auth(){
		$this->host();
  	$this->_mail->Username	= "wulongdao@163.com";
  	$this->_mail->Password	= "wulongdao123"; 
	}

	/**
	 * 发送邮件
	 * @address array('email'=>'name')
	 * @subject
	 * @content
	 * return boolean
	 */
	public function send( Array $address, $subject, $content ){
		try{
			if(is_array($address)){
				foreach($address as $key=>$val){
					$this->_mail->AddAddress( $key, $val );
				}
			}
			$this->_mail->SetFrom('wulongdao@163.com', 'wulongdao');
			$this->_mail->Subject = $subject;
			$this->_mail->MsgHTML( $content );
			$this->_mail->Send();
			return true;
		} catch (phpmailerException $e) {
			//echo $e->errorMessage();
		} catch (Exception $e) {
			//echo $e->getMessage();
		}
		return false;
	}
}
